a = int(input())
if a < 1000 or a > 9999 :
    print(0)
else:
    b = a%10
    c = a//1000
    d = a%100//10
    e = a//100%10
    ab = a%100
    ac = a//100
    ad = a//10%100
    aa = a//10
    ae = a%1000

    if b == 7 or c == 7 or d == 7 or e == 7 or b == 3 or c == 3 or d == 3 or e == 3 or ab == 17 or ab == 13 or ab == 11 or ab == 19 or ac == 17 or ac == 13 or ac == 11 or ac == 19 or ad == 17 or ad == 13 or ad == 11 or ad == 19 or aa == 173 or ae == 173:
        
        max_digit = max(b, c, d, e, ab, ac, ad, aa, ae)
        print(max_digit)
